package flc.ast.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;

import com.blankj.utilcode.util.FragmentUtils;

import java.util.ArrayList;
import java.util.List;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.databinding.ActivityCalculatorBinding;
import flc.ast.fragment.calculator.OrdinaryFragment;
import flc.ast.fragment.calculator.ScienceFragment;

public class CalculatorActivity extends BaseAc<ActivityCalculatorBinding> {

    private List<Fragment> mFragmentList;
    private OrdinaryFragment mOrdinaryFragment;
    private ScienceFragment mScienceFragment;

    @Override
    protected int onCreate() {
        return R.layout.activity_calculator;
    }

    @Override
    protected void initView() {
        mDataBinding.ivCalculatorBack.setOnClickListener(v -> onBackPressed());

        mDataBinding.ivBasics.setOnClickListener(this);
        mDataBinding.ivScientific.setOnClickListener(this);

        mFragmentList = new ArrayList<>();
        mOrdinaryFragment = new OrdinaryFragment();
        mScienceFragment = new ScienceFragment();
        mFragmentList.add(mOrdinaryFragment);
        mFragmentList.add(mScienceFragment);
        FragmentUtils.add(getSupportFragmentManager(), mFragmentList, R.id.flFragment, 0);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.ivBasics://基础计算器
                clearSelection();
                mDataBinding.ivBasics.setImageResource(R.drawable.ajc);
                FragmentUtils.showHide(0, mFragmentList);
                break;
            case R.id.ivScientific://科学计算器
                clearSelection();
                mDataBinding.ivScientific.setImageResource(R.drawable.akx);
                FragmentUtils.showHide(1, mFragmentList);
                break;
        }
    }

    @Override
    protected void initData() {

    }

    private void clearSelection() {
        mDataBinding.ivBasics.setImageResource(R.drawable.ajc1);
        mDataBinding.ivScientific.setImageResource(R.drawable.aky1);
    }

}